package mwt.xml.xdbforms.schemalayer.types;

import java.sql.Time;
import javax.xml.XMLConstants;
import mwt.xml.xdbforms.dblayer.metadata.impl.ColumnMetaData;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Element;


// <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
// #[regen=yes,id=DCE.E81126D6-3804-F80D-B94B-0450DB39762E]
// </editor-fold> 
public class XmlTime extends XmlDate {

  
    public XmlTime(Document doc) {
        super(doc);
    }

    public XmlTime() {
    }

    

    private void buildFragment(ColumnMetaData cmd){

        Element xtype, restrinction, pattern;

        typeName = cmd.getTypeName();
        fragment = doc.createDocumentFragment();

        xtype = doc.createElementNS(XMLConstants.W3C_XML_SCHEMA_NS_URI,"xs:simpleType");
        restrinction = doc.createElementNS(XMLConstants.W3C_XML_SCHEMA_NS_URI,"xs:restriction");
        pattern = doc.createElementNS(XMLConstants.W3C_XML_SCHEMA_NS_URI,"xs:pattern");

        xtype.setAttribute("name", typeName);
        cmd.setXschemaTypeName(typeName);
        restrinction.setAttribute("base", "xs:time");
        pattern.setAttribute("value", "\\p{Nd}{2}:\\p{Nd}{2}:\\p{Nd}{2}");

        xtype.appendChild(restrinction);
        restrinction.appendChild(pattern);
        fragment.appendChild(xtype);

    }

    @Override
    public DocumentFragment getSchemaType(ColumnMetaData cmd) {

        buildFragment(cmd);
        return fragment;

    }

    @Override
    public Object getXSchemaToJavaType(String baseType, String value) {
        Time t = Time.valueOf(value);
        return t;
    }



   
}

